cmake_minimum_required(VERSION 3.12)
project(example-app)
# 设置debug标志, #define DEBUG
# add_definitions(-DDEBUG)
# 设置标准为 C++11
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(contribs/clickhouse-cpp)

# popen()/pclose() are not C++ standards
set(CMAKE_CXX_EXTENSIONS ON)

# 设置构建类型为 Debug
set(CMAKE_BUILD_TYPE Debug)
# 确保启用调试符号
set(CMAKE_CXX_FLAGS_DEBUG "-g")

# 找到PcapPlusPlus库
find_package(PcapPlusPlus REQUIRED)

# 包含目录，以包含头文件
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# 设置所有可执行文件的运行时输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

# 搜索src目录下的所有cpp文件
file(GLOB SRC_FILES src/*.cpp)

# 遍历SRC_FILES列表，即cpp文件，创建可执行文件并链接Pcap++
foreach(SRC_FILE ${SRC_FILES})
    # 从SRC_FILE中以NAME_WE（无后缀）方式，获取文件名，称为EXE_NAME变量
    get_filename_component(EXE_NAME ${SRC_FILE} NAME_WE)
    # 添加可执行文件 
    add_executable(${EXE_NAME} ${SRC_FILE})

    # # 设置单个文件的 可执行文件和.dll等运行时的输出目录
    # set_target_properties(${EXE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

    target_include_directories(${EXE_NAME} PRIVATE contribs/clickhouse-cpp/ contribs/clickhouse-cpp/contrib/absl)

    # 链接Pcap++库（已经通过find_package找到并添加了PcapPlusPlus）
    target_link_libraries(${EXE_NAME} PUBLIC PcapPlusPlus::Pcap++ curl)
    target_link_libraries(${EXE_NAME} PRIVATE clickhouse-cpp-lib pthread)

endforeach()